﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Joyintech.Model.inpiao365;
using Joyintech.BLL.inpiao365;
using System.Data;

namespace Joyintech.Web.inpiao365.theater
{
    public partial class _default : System.Web.UI.Page
    {
        #region 页面变量

        /// <summary>
        /// 城市集合
        /// </summary>
        protected List<movieCity> citylist = null;

        /// <summary>
        /// 区域集合
        /// </summary>
        protected List<movieCityArea> arealist = null;

        /// <summary>
        /// 地区ID
        /// </summary>
        protected string areaid;
        /// <summary>
        /// 城市ID
        /// </summary>
        protected string cityid;

        /// <summary>
        /// 电影院集合
        /// </summary>
        protected List<TheaterViewModel> theaterViewModelList = null;

        /// <summary>
        /// 获得城市的热播电影
        /// </summary>
        protected List<Joyintech.Model.inpiao365.movie> cityHotMovies = null;

        #endregion


        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;
            else
                BindView();
        }

        private void BindView()
        {
            cityid = Request["cityid"] == null ? Request.Cookies["ztyingonde"].Value.ToString(): Request["cityid"];
            areaid = Request["areaid"];

            movieCity_BLL citybll = new movieCity_BLL();
            citylist = citybll.GetModelList(" 1=1 ");

            movieCityArea_BLL areabll = new movieCityArea_BLL();
            arealist = areabll.GetModelList(" CityId='" + cityid + "' ");

            theater_BLL theaterbll = new theater_BLL();
            screenings_BLL screeningsbll = new screenings_BLL();
            List<Joyintech.Model.inpiao365.theater> theaterlist = null;
            if (areaid == null)
            {
                theaterlist = theaterbll.GetModelList(" CityId='" + cityid + "' ");
            }
            else
            {
                theaterlist = theaterbll.GetModelList(" CityId='" + cityid + "' and AreaId='" + areaid + "' ");
            }
            theaterViewModelList = new List<TheaterViewModel>();
            foreach (var item in theaterlist)
            {
                TheaterViewModel model = new TheaterViewModel();
                model.TheaterName = item.TheaterName;
                model.TheaterImg = item.TheaterLogo;
                model.TheaterAdress = item.TheaterAddress;
                model.Phone = item.TheaterTelNo;
                DataSet ds = screeningsbll.GetHotMovie(item.TheaterId.ToString());
                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    model.HotMovie = ds.Tables[0];

                }

                theaterViewModelList.Add(model);
            }

            movie_BLL moviebll = new movie_BLL();
            cityHotMovies = moviebll.GetCityHotMovies(cityid);
        }
    }

    public class TheaterViewModel
    {

        private string theaterName;

        public string TheaterName
        {
            get { return theaterName; }
            set { theaterName = value; }
        }
        private string theaterAdress;

        public string TheaterAdress
        {
            get { return theaterAdress; }
            set { theaterAdress = value; }
        }
        private string phone;

        public string Phone
        {
            get { return phone; }
            set { phone = value; }
        }
        private DataTable hotMovie;

        public DataTable HotMovie
        {
            get { return hotMovie; }
            set { hotMovie = value; }
        }

        private string theaterImg;

        public string TheaterImg
        {
            get { return theaterImg; }
            set { theaterImg = value; }
        }
    }
}